const Stack = require('./stack')

const str1 = '(12)(323)()123(1))'
const str2 = '()(123123)'

function isLegal(str) {
  const items = new Stack()
  for (let i = 0; i < str.length; i++) {
    if (str[i] === '(') {
      items.push(1)
    } else if (str[i] === ')') {
      if (items.isEmpty()) return false
      else items.pop()
    }
  }
  return items.isEmpty()
}

console.log(isLegal(str1), isLegal(str2))
